﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Card.Manager
{
    public partial class LogoEdit : BasePage
    {
        #region
        public int LogoID
        {
            get
            {
                int _id = 0;
                if (Request.QueryString["id"] != null && int.TryParse(Request.QueryString["id"], out _id))
                {
                    return _id;
                }

                return _id;
            }
        }

        private string Img
        {
            get
            {
                return Request.QueryString["img"];
            }
        }
        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.DoInit();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

        }
        #endregion

        #region 方法
        private void DoInit()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["img"]))
            {
                Entity.Logo logo = BLL.LogoManager.GetLogoByImage(Card.Utility.TextUtility.JSUnescape(Request.QueryString["img"].Trim()), null);
                if (logo != null)
                {
                    Response.Redirect(string.Format("LogoEdit.aspx?id={0}",logo.ID));
                }
                else
                {
                    Response.Redirect("LogoEdit.aspx");
                }
            }

            List<BAF.Entity.LookupValue> lstType = Card.Common.LookUpCache.GetLookupValues(CONST.LOOKUP_TYPE.LOGO_TYPE);
            Card.Utility.ControlUtility.BindListControl<BAF.Entity.LookupValue>(this.dropType, lstType, "Value", "LookupCode", false);

            if (this.LogoID > 0)
            {
                Entity.Logo logo = BLL.LogoManager.GetEntity(this.LogoID, null);
                if (logo != null)
                {
                    this.txtName.Text = logo.Name;
                    Card.Utility.ControlUtility.SelectItemByValue(this.dropType, logo.TypeCode);
                    if (!string.IsNullOrEmpty(logo.Image))
                    {
                        this.logo.ImageUrl = Card.Utility.ImageUtilty.GetLogoPath(logo.Image);
                    }
                }
            }
            else
            {
                this.txtName.Text = string.Format("LOGO{0}", DateTime.Now.ToString("yyyyMMddHHmmss"));
            }
        }
        #endregion

    }
}
